#include "DeltaGlider.h"


//watt = amp * volt
/*
float battery_charge_001; 		//this is how much power the batteries have
float battery_charge_Rate; 	//this is how much the batteries get charged
float battery_draw;		//This is how much draw is being put on batteries
bool batteryIsCharging;

void Battery_handle(void);
bool BatteryIsCharging(void);
bool can_charge[3];
*/
//declarations for electrical switches



void DeltaGlider::ActivateAPI (DoorStatus action)
{
	
}

void DeltaGlider::ActivateAPU (DoorStatus action)
{
	
}


void DeltaGlider::set_vars(double charge)
{
	battery_charge_001 = charge;
	battery_charge_Rate_001 = 0;
	battery_draw_001 = 0;
	batteryIsCharging = 0;

for (int x = 0; x <= 3; x++)
	{
		can_charge[x] = 0;
	}
}

void DeltaGlider::set_solarCharge(bool can)
{
	//for now, no damage simulation
	can_charge[0] = !can;
	can_charge[1] = !can;
	can_charge[2] = !can;
	can_charge[3] = !can;
}

bool DeltaGlider::BatteryIsCharging(void)
{
	behindPlanet();
	set_solarCharge(is_behind);
	return is_behind;
}

void DeltaGlider::Battery_handle()
{
	float per_panelCharge = 0;
	if (is_behind == 0) per_panelCharge = 1; //per second
	if (is_behind == 1) per_panelCharge = 0;
	
	battery_charge_001 -= battery_draw_001;
	battery_charge_002 -= battery_draw_002;
	battery_charge_003 -= battery_draw_003;
	battery_charge_004 -= battery_draw_004;
	battery_charge_Rate_001 = 0;
	battery_charge_Rate_002 = 0;
	battery_charge_Rate_003 = 0;
	battery_charge_Rate_004 = 0;


	if (battery_charge_001<5)
		{ can_power1 = 0;  }
	else
		can_power1 =1;

	if (battery_charge_002<5)
		{ can_power2 = 0;  }
	else
		can_power2 =1;

	if (battery_charge_003<5)
		{ can_power3 = 0;  }
	else
		can_power3 =1;

	if (battery_charge_004<5)
		{ can_power4 = 0;  }
	else
		can_power4 =1;

	

		for (int x = 0; x < 3; x++)
		{
			

			if (can_charge[x])
			{
				if (battery_charge_001<101)//added some room for error
				battery_charge_Rate_001 += per_panelCharge;
			}
			if (can_charge[x])
			{
				if (battery_charge_002<101)//added some room for error
				battery_charge_Rate_002 += per_panelCharge;
			}
			if (can_charge[x])
			{
				if (battery_charge_003<101)//added some room for error
				battery_charge_Rate_003 += per_panelCharge;
			}
			if (can_charge[x])
			{
				if (battery_charge_004<101)//added some room for error
				battery_charge_Rate_004 += per_panelCharge;
			}
		}//end for loop
	
	double FPS = oapiGetFrameRate();
	  battery_charge_Rate_001 = ((battery_charge_Rate_001 / FPS) * oapiGetTimeAcceleration ()); //turns to be same per sec, independent of FPS
	//battery_charge += battery_charge_Rate;
}